@Echo off
Echo --------------------------------------------------------------------------------
Echo %~f0 %*

:: File: C:\Documents and Settings\paul\My Documents\Src\Batch\set_IVY.cmd
:: Date: 7:41 AM 12/21/2010

:: Requires the current environment to have DelayedExpansion and 
:: CommandExtensions enabled for Current User {HKCU} or Local Machine {HKLM}:
::    reg add "HKCU\Software\Microsoft\Command Processor" /V EnableExtensions  /T REG_DWORD  /d 0x1 /f
::    reg add "HKCU\Software\Microsoft\Command Processor" /V DelayedExpansion  /T REG_DWORD  /d 0x1 /f
    
Set IVY_HOME=
Set IVYCMD=

If /I "%1" equ "latest" "%~0" apache-ivy-2.2.0
Call :ChkIvy "%~1" apache-ivy-2.2.0 2.2.0 220

Exit /B

:: ----------------------------------------------------------------------------
:: ----------------------------------------------------------------------------

:: ChkIvy Params:
::    User-supplied cmd line parm, 
::    triplets of directory/version tags.
::       The first tag of the triplet must be the actual directory name
::       The second and third tags are aliases

:ChkIvy
Set PARMS=

:ChkIvyLoop
Set PARMS=!PARMS! %2 or %3 or %4 ;
If /I "%~1" equ "%~2" Set IVY_HOME=C:\Program Files\Apache.org\%~2
If /I "%~1" equ "%~3" Set IVY_HOME=C:\Program Files\Apache.org\%~2
If /I "%~1" equ "%~4" Set IVY_HOME=C:\Program Files\Apache.org\%~2
:: If first tag of next triplet is blank, we are done.
:: If we found a HOME, set stuff dependent on HOME.
If "%~5"=="" (
   If "!IVY_HOME!"=="" (
      Echo.
      Echo Looking for a valid IVY version:
      Echo !PARMS!
   ) Else (
      rem :: IVY is a BATCH, not EXE
      Set IVYCMD=!IVY_HOME!\bin\IVY
      Echo IVY_HOME=!IVY_HOME!
      Echo IVYCMD=!IVYCMD!
      "!IVYCMD!" -version
   )
   Exit /B
)
:: Keep %1, scroll next triplet into %2 %3 %4
Shift /2
Shift /2
Shift /2 
Goto :ChkIvyLoop

